package com.hanlink.dsp.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;


import com.edge.pbxdsp.R;
import com.qztech.utils.YzDebug;


/**
 * Created by PeterVon on 2015-11-23.
 */
public class BluetoothDialog extends Dialog {

    private ImageView ivprogress;
    private TextView txtbluetooth;
    private Animation animation;

    public BluetoothDialog(Context context, int resStringId) {
        super(context, com.qztech.sdk.R.style.dialog);
        initView();
        setLoading(resStringId);
        this.show();
    }

    public BluetoothDialog(Context context, int resStringId, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        initView();
        setLoading(resStringId);
    }

    private void initView() {
        WindowManager wm = (WindowManager) getContext().getSystemService(
                Context.WINDOW_SERVICE);
        DisplayMetrics outMetrics = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(outMetrics);
        YzDebug.d("initView", new Throwable());
        setContentView(getLayoutInflater().inflate(com.qztech.sdk.R.layout.dialog_bluetooth, null), new ViewGroup.LayoutParams((int) (outMetrics.widthPixels * 0.9), ViewGroup.LayoutParams.WRAP_CONTENT));
        this.txtbluetooth = (TextView) findViewById(R.id.txt_bluetooth);
        this.ivprogress = (ImageView) findViewById(R.id.iv_progress);
        animation = AnimationUtils.loadAnimation(getContext(), com.hanlink.res.R.anim.loading_bluetooth);
    }

    public void setLoading(int resId) {
        if (ivprogress != null) {
            ivprogress.setImageResource(com.hanlink.res.R.drawable.progress);
            ivprogress.startAnimation(animation);
        }
        setMessage(resId);
    }

    public void setSuccess(int resId) {
        ivprogress.setAnimation(null);
        ivprogress.setImageResource(com.hanlink.res.R.drawable.bluecon_1);
        setMessage(resId);
    }

    public void setFail(int resId) {
        ivprogress.setAnimation(null);
        ivprogress.setImageResource(com.hanlink.res.R.drawable.bluecon_0);
        setMessage(resId);
    }


    public void setMessage(int resId) {
        txtbluetooth.setText(getContext().getString(resId));
    }

}
